Title: SQL W3S (By-BKK) / 109 Unique
Tags: Obsidian_to_Anki

Q: What does the SQL UNIQUE constraint do?
A: It ensures all values in a column are different

Q: True or False: A PRIMARY KEY constraint implies a UNIQUE constraint
A: True

Q: True or False: You can have multiple UNIQUE constraints per table
A: True

Q: True or False: You can have multiple PRIMARY KEY constraints per table
A: False

Q: How would you create a UNIQUE constraint on a column when making a table?
A: Add UNIQUE after the column definition

Q: Which two constraints guarantee uniqueness in a column or set of columns?
A: UNIQUE and PRIMARY KEY constraints

Q: How do you name a UNIQUE constraint in SQL?
A: Use CONSTRAINT constraint_name UNIQUE (columns)

Q: How do you create a UNIQUE constraint on multiple columns?
A: Use UNIQUE (column1, column2) in a table or with CONSTRAINT

Q: How do you add a UNIQUE constraint to an existing table?
A: Use ALTER TABLE table_name ADD UNIQUE (column_name);

Q: How do you add a named UNIQUE constraint on multiple columns to an old table?
A: Use ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2);

Q: How do you drop a UNIQUE constraint in MySQL?
A: Use ALTER TABLE table_name DROP INDEX constraint_name;

Q: How do you drop a UNIQUE constraint in SQL Server, Oracle, or MS Access?
A: Use ALTER TABLE table_name DROP CONSTRAINT constraint_name;

Q: UNIQUE constraint guarantees what?
A: Uniqueness of values in a column or set of columns

Q: Why use UNIQUE constraint in SQL tables?
A: To prevent duplicate values in specified columns

Q: Which is more restrictive: PRIMARY KEY or UNIQUE?
A: PRIMARY KEY (only one per table, always unique and not null)

Q: Reverse card: Ensures all values in a column are different
A: What does the UNIQUE constraint do in SQL?

Q: Reverse card: ALTER TABLE Persons DROP INDEX UC_Person;
A: How do you remove a UNIQUE constraint in MySQL?

Q: Reverse card: ALTER TABLE Persons DROP CONSTRAINT UC_Person;
A: How do you remove a UNIQUE constraint in SQL Server, Oracle, or MS Access?